<?php
namespace app\manage\controller;
obj('api/Api')->isSession('manage_system','index.php?r=manage/login/index');
class caijiController extends \app\base\controller\BaseController
{
    public function index()
    {
    	$this->pagetext=array("优惠券","管理优惠券和采集优惠券");
    	$where[] = "1";
        $baseurl = "index.php?r=manage/caiji/index";
        $Page = obj('api/ApiData')->page("50", "youhuiquan", $where, "`id` DESC", $baseurl);
        $this->Page = $Page;
        $this->display();
    }
	
	    public function union()
    {
    	$this->pagetext=array("值得买联盟","采集和新增管理值得买");
    	$where[] = "1";
        $baseurl = "index.php?r=manage/caiji/union";
        $Page = obj('api/ApiData')->page("50", "goods", $where, "`date` DESC", $baseurl);
        $this->Page = $Page;
        $this->display();
    }

    
    public function dtk(){


    	$this->display();

    }
	    public function dtkup(){


    	$this->display();

    }
	
	
	    public function duomai(){


    	$this->display();

    }
    
	    public function yqfgy(){


    	$this->display();

    }
	    public function yqfgygj(){


    	$this->display();

    }

    public function dtkcaiji(){
    	 $page=$this->arg('nowpage');
	      if(!$page){
	        $page='1';
	      }
	      $t=$this->arg('t');
	      $e=$this->arg('e');
	      $now=$page;
	      if($e==$now){ 
	        exit('ok');
	     }
		 include CONFIG_PATH . 'apiset.php';
    	 $token= new \ZhiCms\ext\weixin;
         $host = 'https://openapi.dataoke.com/api/goods/get-goods-list';
         $appKey = $api['appKey'];//应用的key
        $appSecret = $api['appSecret'];//应用的Secret
        //默认必传参数
        $datas = [
    'appKey' => $appKey,
    'version' => '1.1.0',
      ];
     //加密的参数
	  $datas['pageId']=$page;
     $datas['sign'] = $this->makeSign($datas,$appSecret);
	 //拼接请求地址
     $url = $host .'?'. http_build_query($datas);
		 $ret=obj("api/Api")->object_array(json_decode($token->http($url)));
$a = obj('api/ApiData')->thisquery('BEGIN');
$count=count($ret['data']['list'])-1;
 for($key='0';$key<=$count;$key++){
	 $itemiid=$ret['data']['list'][$key]['goodsId'];
	 $where[]="`goodsId` ='{$itemiid}'";
	   $chongfu=obj("api/Apidata")->Data_Select("youhuiquan",$where,'goodsId');
	   
	 if($chongfu['goodsId']==0||$chongfu['goodsId']==null||$chongfu['goodsId']==""){
		    $data['goodsId']=$ret['data']['list'][$key]['goodsId'];
         	$data['itemLink']=$ret['data']['list'][$key]['itemLink'];
			$data['title']=$ret['data']['list'][$key]['title'];
         	$data['dtitle']=$ret['data']['list'][$key]['dtitle'];
         	$data['desc']=$ret['data']['list'][$key]['desc'];
         	$data['cid']=$ret['data']['list'][$key]['cid'];
         	$data['mainPic']=$ret['data']['list'][$key]['mainPic'];
         	$data['marketingMainPic']=$ret['data']['list'][$key]['marketingMainPic'];
         	$data['originalPrice']=$ret['data']['list'][$key]['originalPrice'];
         	$data['actualPrice']=$ret['data']['list'][$key]['actualPrice'];
         	$data['discounts']=$ret['data']['list'][$key]['discounts'];
         	$data['commissionType']=$ret['data']['list'][$key]['commissionType'];
         	$data['commissionRate']=$ret['data']['list'][$key]['commissionRate'];
         	$data['couponLink']=$ret['data']['list'][$key]['couponLink'];
			$data['couponTotalNum']=$ret['data']['list'][$key]['couponTotalNum'];
			$data['couponReceiveNum']=$ret['data']['list'][$key]['couponReceiveNum'];
			$data['couponEndTime']=$ret['data']['list'][$key]['couponEndTime'];
			$data['couponStartTime']=$ret['data']['list'][$key]['couponStartTime'];
         	$data['couponPrice']=$ret['data']['list'][$key]['couponPrice'];
			$data['couponConditions']=$ret['data']['list'][$key]['couponConditions'];
			$data['monthSales']=$ret['data']['list'][$key]['monthSales'];
         	$data['shopType']=$ret['data']['list'][$key]['shopType'];
         	$data['shopName']=$ret['data']['list'][$key]['shopName'];
			$data['hotPush']=$ret['data']['list'][$key]['hotPush'];
			$data['laiyuan']=2;
            obj("api/Apidata")->Inserts("youhuiquan",$data);			
	 }/*else{
		 $sql = "UPDATE `{pre}youhuiquan`  SET  originalPrice='{$ret['data']['list'][$key]['originalPrice']}',actualPrice='{$ret['data']['list'][$key]['actualPrice']}' ,discounts='{$ret['data']['list'][$key]['discounts']}',couponPrice='{$ret['data']['list'][$key]['couponPrice']}',commissionType='{$ret['data']['list'][$key]['commissionType']}',commissionRate='{$ret['data']['list'][$key]['commissionRate']}',couponReceiveNum='{$ret['data']['list'][$key]['couponReceiveNum']}',monthSales='{$ret['data']['list'][$key]['monthSales']}',hotPush='{$ret['data']['list'][$key]['hotPush']}'  WHERE  `goodsId` =  '{$ret['data']['list'][$key]['goodsId']}'";
	   obj('api/ApiData')->thisquery($sql); 
	 }*/
	 
if($key%100==0){
    //每1w条提交一次
    $d = obj('api/ApiData')->thisquery('COMMIT');
    $e = obj('api/ApiData')->thisquery('BEGIN');
}	
 echo 'ok';
 }
$f = obj('api/ApiData')->thisquery('COMMIT');

    }
	
	

	

	
	    public function yqfgycaiji(){
			header('Content-Type:text/json;charset=utf-8');
    	 $page=$this->arg('nowpage');
	      if(!$page){
	        $page='1';
	      }
          $type=$this->arg('type');
	      if(!$type){
	        $type='0';
	      }
	      $t=$this->arg('t');
	      $e=$this->arg('e');
	      $now=$page;
	      if($e==$now){ 
	        exit('ok');
	     }
		 
		 include CONFIG_PATH . 'apiset.php';
    	 //$token= new \framework\ext\weixin;
        
	 //拼接请求地址
	 $token= new \ZhiCms\ext\weixin;
	 //$ret=file_get_contents("http://o.yiqifa.com/servlet/interface?method=yiqifa.product.nonelink.list.get&app_key=FHEPI3TYHF&app_secret=2112a659536d1c597084&pageSize=200&pageIndex=".$page);
	//$ret=json_decode(iconv("gb2312","utf-8//IGNORE",$token->http($url)),true);
	$url="http://o.yiqifa.com/servlet/interface?method=yiqifa.product.nonelink.list.get&encoding=UTF-8&mallType=".$type."&app_key=".$api['app_key']."&app_secret=".$api['app_secret']."&pageSize=200&pageIndex=".$page;
	$ret=obj("api/Api")->object_array(json_decode($token->http($url),true));
	//$ret=obj("api/Api")->object_array(json_decode(iconv("gb2312","utf-8//IGNORE",$token->http($url)),true));
	//$ret =  preg_replace('/[\x00-\x1F\x80-\x9F]/u', '', json_decode(trim(json_encode($this->encodeConvert($ret,'gb2312','utf-8'), JSON_UNESCAPED_SLASHES),chr(239).chr(187).chr(191)),true));
	//echo $ret['msg'];

$a = obj('api/ApiData')->thisquery('BEGIN');

 
 
 for($key='0';$key<=200;$key++){
	 $where[]="`id` ='{$ret['result']['data'][$key]['id']}'";
	 $chongfu=obj("api/Apidata")->Data_Select("goods",$where);
	 if(!$chongfu){
		 if($ret['result']['data'][$key]['mallName']!="" || $ret['result']['data'][$key]['mallId']!=""){
		  $data['id']=$ret['result']['data'][$key]['id'];
		  $data['mallName']=$ret['result']['data'][$key]['mallName'];
		  $data['monthSaleCount']=$ret['result']['data'][$key]['monthSaleCount'];
		  $data['mobileCampaignId']=$ret['result']['data'][$key]['mobileCampaignId'];
		  $data['salesVolume']=$ret['result']['data'][$key]['salesVolume'];
		  $data['mallId']=$ret['result']['data'][$key]['mallId'];
		  $data['description']=$ret['result']['data'][$key]['description'];
		  $data['isRelatedSales']=$ret['result']['data'][$key]['isRelatedSales'];
		  $data['productName']=$ret['result']['data'][$key]['productName'];
		  $data['pcPrice']=$ret['result']['data'][$key]['pcPrice'];
		  $data['pcCommission']=$ret['result']['data'][$key]['pcCommission'];
		  $data['selfSupport']=$ret['result']['data'][$key]['selfSupport'];
		  $data['storeName']=$ret['result']['data'][$key]['storeName'];
		  $data['2ndCategoryId']=$ret['result']['data'][$key]['2ndCategoryId'];
		  $data['startTime']=$ret['result']['data'][$key]['startTime'];
		  $data['brand']=$ret['result']['data'][$key]['brand'];
		  $data['isCoupon']=$ret['result']['data'][$key]['isCoupon'];
		  $data['ispostFree']=$ret['result']['data'][$key]['ispostFree'];
		  $data['mobileComissionRate']=$ret['result']['data'][$key]['mobileComissionRate'];
		  $data['mobilePriceOri']=$ret['result']['data'][$key]['mobilePriceOri'];
		  $data['productId']=$ret['result']['data'][$key]['productId'];
		  $data['pcProductUrl']=$ret['result']['data'][$key]['pcProductUrl'];
		  $data['1stCategoryName']=$ret['result']['data'][$key]['1stCategoryName'];
		  $data['pcComissionRate']=$ret['result']['data'][$key]['pcComissionRate'];
		  $data['mobliePrice']=$ret['result']['data'][$key]['mobliePrice'];
		  $data['mallType']=$ret['result']['data'][$key]['mallType'];
		   $data['imgUrl']=$ret['result']['data'][$key]['imgUrl'];
		  $data['1stCategoryId']=$ret['result']['data'][$key]['1stCategoryId'];
		  $data['pcCampaignId']=$ret['result']['data'][$key]['pcCampaignId'];
		  $data['2ndCategoryName']=$ret['result']['data'][$key]['2ndCategoryName'];
		  $data['pcPriceOri']=$ret['result']['data'][$key]['pcPriceOri'];
		  $data['endTime']=$ret['result']['data'][$key]['endTime'];
		  $data['mobileCommission']=$ret['result']['data'][$key]['mobileCommission'];
		  $data['status']=$ret['result']['data'][$key]['status'];
		  $data['couponAmount']=$ret['result']['data'][$key]['couponAmount'];
		  $data['couponUrl']=$ret['result']['data'][$key]['couponUrl'];
		  $data['leftCount']=$ret['result']['data'][$key]['leftCount'];
		  $data['threshhold']=$ret['result']['data'][$key]['threshhold'];
          $data['date']=date('Y-m-d H:i:s',time());
            obj("api/Apidata")->Inserts("goods",$data);	//入库
			$wheres[]="`1stCategoryName` ='{$ret['result']['data'][$key]['1stCategoryName']}' and `mallType` ='{$ret['result']['data'][$key]['mallType']}' and `mallName` ='{$ret['result']['data'][$key]['mallName']}'";
	 $cf=obj("api/Apidata")->Data_Select("category",$wheres);
	 if(!$cf){
		   $datas['mallType']=$ret['result']['data'][$key]['mallType'];
		   $datas['mallName']=$ret['result']['data'][$key]['mallName'];
		  $datas['1stCategoryName']=$ret['result']['data'][$key]['1stCategoryName'];
            obj("api/Apidata")->Inserts("category",$datas);	//入库	
	 }
		 }
		  		
	 //}else{
		 //$sql = "UPDATE `{pre}goods`  SET  originalPrice='{$ret['data']['list'][$key]['originalPrice']}',actualPrice='{$ret['data']['list'][$key]['actualPrice']}' ,discounts='{$ret['data']['list'][$key]['discounts']}',couponPrice='{$ret['data']['list'][$key]['couponPrice']}',commissionType='{$ret['data']['list'][$key]['commissionType']}',commissionRate='{$ret['data']['list'][$key]['commissionRate']}',couponReceiveNum='{$ret['data']['list'][$key]['couponReceiveNum']}',monthSales='{$ret['data']['list'][$key]['monthSales']}',hotPush='{$ret['data']['list'][$key]['hotPush']}'  WHERE  `goodsId` =  '{$ret['data']['list'][$key]['goodsId']}'";
	   //obj('api/ApiData')->thisquery($sql); 
	 }
	$sql = "DELETE FROM `{pre}category` WHERE (`1stCategoryName`,`mallName`) IN (SELECT `1stCategoryName`,`mallName` FROM (SELECT `1stCategoryName`,`mallName` FROM `{pre}category` GROUP BY `1stCategoryName`,`mallName` HAVING COUNT(*)>1) s1) AND id NOT in (SELECT id FROM (SELECT id FROM `{pre}category` GROUP BY `1stCategoryName`,`mallName` HAVING COUNT(*)>1) s2)";
	 obj('api/ApiData')->thisquery($sql);
	 
if($key%100==0){
    //每1w条提交一次
    $d = obj('api/ApiData')->thisquery('COMMIT');
    $e = obj('api/ApiData')->thisquery('BEGIN');
}		
 echo 'ok';
 }
$f = obj('api/ApiData')->thisquery('COMMIT');

    }


	

    public function addunion(){

    	if(!IS_POST){
    		$this->display();
    		exit;
    	}else{

    	  //$data = obj('api/Api')->Form($this->POSTarg());
    	  //self::ChecktbkForm();
		  $data['mallName']=$this->arg("mallName");
		  $data['productName']=$this->arg("productName");
		  $data['1stCategoryName']=$this->arg("1stCategoryName");
		  $data['pcPrice']=$this->arg("pcPrice");
		  $data['pcPriceOri']=$this->arg("pcPriceOri");
		  $data['isCoupon']=$this->arg("isCoupon");
		  $data['pcComissionRate']=$this->arg("pcComissionRate");
	      $data['mallType']=$this->arg("mallType");
          $data['imgUrl']=$this->arg("imgUrl");
		  $data['couponUrl']=$this->arg("url");
		  $data['content']=$this->arg("content");
          $data['date']=date('Y-m-d H:i:s',time());
			
    	    obj('api/ApiData')->Inserts('goods', $data);
            //echo json_encode(array("info" => $data, "status" => "y","windows"=>"pop"));
		echo json_encode(array("info" => "添加成功", "status" => "y"));

    	}
    }
	    public function editorunion(){

    	if(!IS_POST){
    		$this->pagetext=array("值得买联盟","编辑值得买");
    		$id=$this->arg("id");
            $where[]="`id` ={$id}";
            $ret=obj("api/Apidata")->Data_Select("goods",$where);
			$this->html='<input type="hidden" name="id" value="'.$ret['id'].'" />';
            $this->ret=$ret;
			$this->display();
			exit;
    	}else{
    	  
    	  $data['mallName']=$this->arg("mallName");
		  $data['productName']=$this->arg("productName");
		  $data['1stCategoryName']=$this->arg("1stCategoryName");
		  $data['pcPrice']=$this->arg("pcPrice");
		  $data['pcPriceOri']=$this->arg("pcPriceOri");
		  $data['isCoupon']=$this->arg("isCoupon");
		  $data['pcComissionRate']=$this->arg("pcComissionRate");
	      $data['mallType']=$this->arg("mallType");
          $data['imgUrl']=$this->arg("imgUrl");
		  $data['couponUrl']=$this->arg("url");
		  $data['content']=$this->arg("content");
          $data['date']=date('Y-m-d H:i:s',time());
		  $id=$this->arg("id");
		  $where[]="  `id` ={$id} ";
    		obj("api/Apidata")->Data_Updata("goods",$data,$where);
    		echo json_encode(array("info" => "编辑成功", "status" => "y"));

    	}
    }
	    public function deleteunion(){
        error_reporting('0');
    	$id=$this->arg("id");
    	$where="  `id` ={$id}";
        obj('api/ApiData')->Deletethis('goods', $where);//需要删除的数据
        exit(json_encode(array("info" => "删除成功", "status" => "y")));
    }
	
	 	public function ChecktbkForm(){
 		if(!$this->arg("url")){
 			exit(json_encode(array("info" => "请输入宝贝网址", "status" => "n")));
 		}
 		if(!$this->arg('itemsurl')){
 			exit(json_encode(array("info" => "请输入宝贝链接", "status" => "n")));
 		}
 		if(!$this->arg('wa')){
 			exit(json_encode(array("info" => "请输入文案", "status" => "n")));
 		}
 		if(!$this->arg('taoToken')){
 			exit(json_encode(array("info" => "请输入宝贝口令", "status" => "n")));
 		}
 	}

	
	
	
	
	
	
	
	
    
    public function duomailist(){
		 error_reporting('0');
			include CONFIG_PATH . 'apiset.php';
       //1.获取xml数据 
     $xmldata=file_get_contents("https://www.duomai.com/api/ads.php?hash=e50f2f2a43b287ec18c80756ebb3fb7c&action=getApplyAds");
     $xmlstring = simplexml_load_string($xmldata, 'SimpleXMLElement', LIBXML_NOCDATA);
     $value_array = json_decode(json_encode($xmlstring),true); 
	 $data =json_encode($value_array, JSON_UNESCAPED_UNICODE);
    $json = json_decode($data, true);//再次解析参数获得数组
     $result=array_shift($json);//减去第一组无用数组
    $ret=obj("api/Api")->object_array($json);
	exit(strip_tags(json_encode($ret, JSON_UNESCAPED_UNICODE)));
     /*for($key='0';$key<=100000;$key++){
		 $where[]="`ads_id` ='".$ret['fix_'.$key]['ads_id']."'";
	 $chongfu=obj("api/Apidata")->Data_Select("duomai",$where);
	if($chongfu['ads_id']=="" || $chongfu['ads_id']==0 || $chongfu['ads_id']==null){
		$shuju['ads_id']=$ret['fix_'.$key]['ads_id'];
		$shuju['ads_name']=$ret['fix_'.$key]['ads_name'];
		$shuju['channel']=$ret['fix_'.$key]['channel'];
		$shuju['status']=$ret['fix_'.$key]['status'];
		$shuju['applay_mode']=$ret['fix_'.$key]['applay_mode'];
		$shuju['hide']=$ret['fix_'.$key]['hide'];
		$shuju['type']=$ret['fix_'.$key]['type'];
		$shuju['cate_name']=$ret['fix_'.$key]['cate_name']=="" || $ret['fix_'.$key]['cate_name']==null ?"":$ret['fix_'.$key]['cate_name'];
		$shuju['ads_endtime']=$ret['fix_'.$key]['ads_endtime'];
		$shuju['ads_commission']=$ret['fix_'.$key]['ads_commission'];
		$shuju['site_url']=$ret['fix_'.$key]['site_url'];
		$shuju['site_logo']=$ret['fix_'.$key]['site_logo'];
		$shuju['site_description']=$ret['fix_'.$key]['site_description']=="" || $ret['fix_'.$key]['site_description']==null ? "":$ret['fix_'.$key]['site_description'];
		$shuju['adser']=$ret['fix_'.$key]['adser'];
		$shuju['country']=$ret['fix_'.$key]['country'];
		obj("api/Apidata")->Inserts("duomai",$shuju);
	 }

 echo 'ok';
    }*/
	
	
	


    	
  }

public function duomaigy(){
	 error_reporting('0');
       //1.获取xml数据 
	   include CONFIG_PATH . 'apiset.php';
	    $page=$this->arg('nowpage');
	      if(!$page){
	        $page='1';
	      }
	      $t=$this->arg('t');
	      $e=$this->arg('e');
	      $now=$page;
	      if($e==$now){ 
	        exit('ok');
	     }
		 
     $xmldata=file_get_contents("https://www.duomai.com/api/ads.php?hash=".$api['hash']."&action=getHighProductions&limit=".$page.",1000");
     $xmlstring = simplexml_load_string($xmldata, 'SimpleXMLElement', LIBXML_NOCDATA);
     $value_array = json_decode(json_encode($xmlstring),true); 
	 $datas =json_encode($value_array, JSON_UNESCAPED_UNICODE);
    $ret = json_decode($datas, true);//再次解析参数获得数组
     //$result=array_shift($json);//减去第一组无用数组
    //$ret=obj("api/Api")->object_array($json);
	
	 



$a = obj('api/ApiData')->thisquery('BEGIN');
 for($key='0';$key<=10000;$key++){
	 
	        $data['sku']=$ret['products']['fix_'.$key]['sku'];
         	$data['name']=$ret['products']['fix_'.$key]['name'];
			$data['ads_id']=$ret['products']['fix_'.$key]['ads_id'];
         	$data['old_price']=$ret['products']['fix_'.$key]['old_price'];
         	$data['new_price']=$ret['products']['fix_'.$key]['new_price'];
         	$data['end_time']=$ret['products']['fix_'.$key]['end_time'];
         	$data['img']=$ret['products']['fix_'.$key]['img'];
         	$data['url']=$ret['products']['fix_'.$key]['url'];
         	$data['category']=$ret['products']['fix_'.$key]['category'];
         	$data['status']=$ret['products']['fix_'.$key]['status'];
			$data['rate']=$ret['products']['fix_'.$key]['rate'];
			$data['date']=date('y-m-d h:i:s',time());
            obj("api/Apidata")->Inserts("items",$data);			
	
	 
if($key%100==0){
    //每1w条提交一次
    $d = obj('api/ApiData')->thisquery('COMMIT');
    $e = obj('api/ApiData')->thisquery('BEGIN');
}		
 echo 'ok';
 }
$f = obj('api/ApiData')->thisquery('COMMIT');









    	exit(strip_tags(json_encode($ret['total'], JSON_UNESCAPED_UNICODE)));
}







   //上下架处理
   public function lock(){
        $id=$this->arg("id");
        $lock=$this->arg("lock");
        $where[]="`id` ={$id}";
        if($lock=="1"){ 
        $data['lock']="1";
        obj("api/Apidata")->Data_Updata("youhuiquan",$data,$where);
        exit(json_encode(array("info" => "下架成功", "status" => "y")));
       }elseif($lock=="2"){
        $data['lock']="0";
        obj("api/Apidata")->Data_Updata("youhuiquan",$data,$where);
        exit(json_encode(array("info" => "上架成功", "status" => "y")));

       }

   }
       public function del(){
        error_reporting('0');
    	$id=$this->arg("id");
    	$where="  `id` ={$id}";
        obj('api/ApiData')->Deletethis('youhuiquan', $where);//删除数据
        exit(json_encode(array("info" => "删除成功", "status" => "y")));
    }
	public function overdue(){//一键删除过期产品
	  include CONFIG_PATH . 'siteconfig.php';
	  $tbk= new \ZhiCms\ext\Tbk;
		$where[]="`id` !=0";
    	$shuju=obj("api/Apidata")->Data_Select("youhuiquan",$where,"`id` DESC ");
		$count=count($shuju);
		for($key='0';$key<=$count;$key++){
	  $info=$tbk->getinfo($Siteinfo['appkey'],$Siteinfo['secretKey'],$shuju[$key]['goodsId']);
	   if(!$info){
		 $sql = "DELETE FROM `{pre}youhuiquan`  WHERE  `id` =  '{$shuju[$key]['id']}'";
	   obj('api/ApiData')->thisquery($sql);     
	   }
		}
        exit(json_encode(array("info" => "更新成功", "status" => "y")));
    }

   public function cid($cid){

    	 if($cid=="1"){
    	 	return "女装";
    	 }
    	  if($cid=="2"){
    	 	return "母婴";
    	 }
    	  if($cid=="3"){
    	 	return "化妆品";
    	 }
    	  if($cid=="4"){
    	 	return "居家";
    	 }
    	  if($cid=="5"){
    	 	return "鞋包配饰";
    	 }
    	  if($cid=="6"){
    	 	return "美食";
    	 }
    	  if($cid=="7"){
    	 	return "文体车品";
    	 }
    	  if($cid=="8"){
    	 	return "数码家电";
    	 }
    	  if($cid=="9"){
    	 	return "男装";
    	 }
    	   if($cid=="10"){
    	 	return "内衣";
    	 }
		 if($cid=="12"){
            return "配饰";
         }
         if($cid=="11"){
            return " 箱包";
         }
         if($cid=="14"){
            return '家装家纺';
         }
          if($cid=="13"){
            return '户外运动';
         }
    }
	
	public function makeSign($data, $appSecret)
{
    ksort($data);
    $str = '';
    foreach ($data as $k => $v) {

        $str .= '&' . $k . '=' . $v;
    }
    $str = trim($str, '&');
    $sign = strtoupper(md5($str . '&key=' . $appSecret));
    return $sign;
}
}